<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1251">
<object ID="mysink" CLASSID="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"></object>
<hta:application id="hta" applicationname="HTAPrEx"
contextmenu="no"
innerborder="no"
maximizebutton="yes"
minimizebutton="yes"
navigable="yes"
scroll="no"
scrollflat="yes"
selection="yes"
showintaskbar="yes"
singleinstance="no"
maximized="yes"
sysmenu="yes"
version="0.00000000000000000000d"
windowstate="maximize"
>
<LINK REL=StyleSheet HREF="css\jquery_ui_custom.css" TYPE="text/css">
<LINK REL=StyleSheet HREF="css\mystyle.css" TYPE="text/css">
<LINK REL=StyleSheet HREF="css\ui.tabs.css" TYPE="text/css">
<LINK REL=StyleSheet HREF="css\tablesorter.style.css" TYPE="text/css">
<script type="text/javascript" src="js\jquery-1.3.2-mod.js"></script>
<script type="text/javascript" src="js\jquery-ui-1.7.2.custom-mod.js"></script>
<script type="text/javascript" src="js\jquery.ui.tabs.js"></script>
<script type="text/javascript" src="js\JQuery.ContextMenu.js"></script>
<script type="text/javascript" src="js\jquery.colorize-1.6.0.js"></script>
<script type="text/javascript" src="js\jquery.tablesorter-mod2.js"></script>
<script type="text/javascript" src="js\jquery.uitablefilter.js"></script>

<title>HTAPrEx 0.00000000000000000eeeeEEEE </title>

<script language="VBScript">
<!--
function FormatDate(objLastLogon)
	on error resume next
	intLastLogonTime = objLastLogon.HighPart * (2^32) + objLastLogon.LowPart
	intLastLogonTime = intLastLogonTime / (60 * 10000000)
	intLastLogonTime = intLastLogonTime / 1440
	FormatDate=intLastLogonTime + #1/1/1601#	
End function 
//-->
</script>
<script language="JScript">
<!--
//active properties araay
var Active=[]
//active computer sets to local
Active.Computer=new ActiveXObject("WScript.Network").Name
//active computer sets to ""
Active.Process=""
//Select Computer Propterties using LDAP, (LdapPropName,ColumnWidth)
LdapProps=new Array('Name',150,'dNSHostName',185,'lastLogon',220,'logonCount',60,'operatingSystem',155,'operatingSystemServicePack',100,'operatingSystemVersion',100,'Description',70,'Location',70)
//Processes Propterties
ProcProps=new Array('Caption','str',150,'ProcessId','str',45,'WorkingSetSize','int',90,'PrivatePageCount','int',115,'VirtualSize','int',105,'ExecutablePath','str',500)
//after selecting any tab after ResizeTimeout call tabsSize function for proper selected tab scrolling
var ResizeTimeout=200
var debug=1

var tables=["tabla_computers","tabla","tabla2"]//tablenames

var bottom_space=70//space between  processes table and windows start bar
var right_space=100//space between  processes table and right side
var StartPanelPosition=screen.availHeight;

//
var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;
var ActiveComputer=1


//decalring ArrType - type of array
Array.prototype.ArrType=""
//new array for computers list
var objComputersList = new Array();
objComputersList.ArrType="ArrComputersList"//
//new array for processes list
var ArrProcessesList=new Array();
ArrProcessesList.ArrType="ArrProcessesList"//
//modified array push function
function ArrPush(){	
	if(this.ArrType=="ArrProcessesList"){
		this.length+=1
		this[this.length-1]=new Array()
		for(var zz=0;zz<=(ProcProps.length/3)-1;zz++){eval("this[this.length-1]."+ProcProps[zz*3]+"=''");}//extend array element with even ProcProps elements
	}
	else if(this.ArrType=="ArrComputersList"){
		this.length+=1
		this[this.length-1]=new Array()
		for(var zz=0;zz<=(LdapProps.length-1)/2;zz++){eval("this[this.length-1]."+LdapProps[zz*2]+"=''");}//extend array element with even LdapProps elements
	}
	else{
		var n = this.length >>> 0;
		for (var i = 0; i < arguments.length; i++) {
			this[n] = arguments[i];
			n = n + 1 >>> 0;
		}
		this.length = n;
		return n;
	}
}	
Array.prototype.push = ArrPush; //declaring my push prototype

var Avaible=function(name){ //
	var objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" + name + "'");	
	for(var _enum = new Enumerator(objPing);!_enum.atEnd();_enum.moveNext()){
        var objStatus=_enum.item();
		//window.alert("Pinging status is " + objStatus.StatusCode+" of "+name)
        if(objStatus.StatusCode == null || objStatus.StatusCode != 0){return false;}
        if(objStatus.StatusCode == 0){return true;}
    }
}

function GetDomainComputers(){
	// ADSI
	var i=1;	

	
	//clear computers table
	$("#"+eval("tables[0]")).remove();

	//creating tabla
	$("#divPCList").append("<table id='"+eval("tables[0]")+"'></table>");
	$("#"+eval("tables[0]")).append("<tbody id='body0'></tbody>");
	
	var objConnection = new ActiveXObject("ADODB.Connection");	
	with(objConnection){
		Provider = "ADsDSOObject";
		Open("Active Directory Provider");
	}
	
	try
	{
		var oRoot = GetObject("LDAP://rootDSE");
		var objCommand = new ActiveXObject("ADODB.Command");
		objCommand.ActiveConnection = objConnection;	
		//select all  domain computers
		var CommandText = "SELECT "
		//enumerate ldap properties to select			
		for(var zz=0;zz<=(LdapProps.length-3)/2;zz++){CommandText=CommandText+LdapProps[zz*2]+","}//add all fields of LdapProps to select except one last
		CommandText=CommandText+LdapProps[LdapProps.length-2]//add field last without ,
		CommandText = CommandText+" FROM 'LDAP://"+oRoot.Get("defaultNamingContext")+"' WHERE objectClass='computer'" //full query ready!
		objCommand.CommandText=CommandText;
		//select 'em
		var objRecordSet = objCommand.Execute();
		//"ADODB.Recordset"
		objRecordSet.MoveFirst();
		
		while (!objRecordSet.EOF)
		{
			$("#body0").append("<tr style='back1' id='table_computers_row_"+i+"'>");
			objComputersList.push();
			//add  contextmenu handler
			var td_beg="<td class='tabla1' onmouseDown='ContextMenu_Computers("+i+")'"
			var td_right=td_beg+" align='right'"				

			//fill a single row with LdapProps
			for(var zz=0;zz<=(LdapProps.length-1)/2;zz++){							
				if(zz==2){var ADOVal=FormatDate(eval('objRecordSet.Fields("'+LdapProps[zz]+'").Value'))}
				else{var ADOVal=eval('objRecordSet.Fields("'+LdapProps[zz*2]+'").Value')}				
				eval('objComputersList['+(i-1)+'].'+LdapProps[zz*2]+'="'+ADOVal+'"');
				$("#table_computers_row_"+i).append(td_beg  +" width="+LdapProps[(zz*2)+1]+">"+eval('objComputersList['+(i-1)+'].'+LdapProps[zz*2])+"</td>");
			}
			i+=1;			
			objRecordSet.MoveNext();
		}
		$("#"+eval("tables[0]")).colorize({bgColor:'#EAF6CC', hoverColor:'#f6a828', hiliteColor:'red', rows:true});
		$("#"+eval("tables[0]")).tablesorter({headersTable:'tabla_h_computers',afterSortFunction:"$('#"+eval("tables[0]")+"').colorize({bgColor:'#EAF6CC', hoverColor:'#f6a828', hiliteColor:'red', rows:true});"});
	}
	catch(e){//going local mode
		var objNetwork = new ActiveXObject("WScript.network")
		//hide first tab with computer
		$('#tabs').tabs('select', 1);
		$('#tabs').tabs('disable', 0); 
		//add only local computer
		objComputersList.push();
		objComputersList[i-1].Name=objNetwork.ComputerName;
		}
	finally{
		ActiveComputer=0;
		GetProcesses(ActiveComputer);
	}
	
}

function GetProcessInfo(computer_id,process_id){	
	$("#"+eval("tables[2]")).remove();
	//creating tabla
	$("#divInfoList").append("<table id='"+eval("tables[2]")+"'></table>");
	var td_beg="<td class='tabla1' "
	var td_right=td_beg+" align='right'"	
	var row=0
	//try
	var objWMIService = GetObject("winmgmts:\\\\" + objComputersList[computer_id].Name + "\\root\\CIMV2");
	var query="SELECT * FROM Win32_Process WHERE ProcessId="+ArrProcessesList[process_id].ProcessId	
	//alert(query)
	//get process info
	var colItems = objWMIService.ExecQuery(query, "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);
	
	//process enumerator
	for (var enumItems = new Enumerator(colItems); !enumItems.atEnd(); enumItems.moveNext()) {
		var objItem = enumItems.item();	
		//get Win32_Process
		var objClass = objWMIService.Get("Win32_Process");
		//process info enumerator //get Win32_Process Properties
		for (var enumItems2 = new Enumerator(objClass.Properties_); !enumItems2.atEnd(); enumItems2.moveNext()) {
			var objItem2 = enumItems2.item();
			//process info
			//enum subclasses of win32 process
			$("#"+eval("tables[2]")).append("<tr style='back1' id='table2_row_"+row+"'>");
			$("#table2_row_"+row).append(td_right	+">"+objItem2.Name+"</td>");
			$("#table2_row_"+row).append(td_beg  	+">"+eval("objItem."+objItem2.Name)+"</td>");
			row+=1;
			//alert(objItem2.Name+":"+eval("objItem."+objItem2.Name))
		}
	}	
	//colorize tabla
	$("#"+eval("tables[2]")).colorize({bgColor:'#EAF6CC', hoverColor:'#f6a828', hiliteColor:'red', rows:true});
}

function GetProcesses(id){
	//
	if(!Avaible(objComputersList[id].Name)){
		alert(objComputersList[id].Name+" is not avaible");
		//document.getElementById('PCComboBox').value=ActiveComputer
		return false;
	}
	ActiveComputer=id
	//
	try{
		var objWMIService = GetObject("winmgmts:{impersonationLevel=Impersonate}\\\\" + objComputersList[id].Name + "\\root\\CIMV2");
		
		var CommandText = "SELECT "
		//enumerate processes properties to select			
		for(var zz=0;zz<=(ProcProps.length/3)-2;zz++){CommandText=CommandText+ProcProps[zz*3]+","}//add all fields of ProcProps to select except one last
		CommandText=CommandText+ProcProps[ProcProps.length-3]//add field last without ,
		CommandText = CommandText+" FROM Win32_Process" //full query ready!						
		var colItems = objWMIService.ExecQuery(CommandText, "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);  
	}
	catch(e){
		alert("Could not connect with "+objComputersList[id].Name);
		document.getElementById('PCComboBox').value=ActiveComputer
		return	false;
	}
	//clear table named tabla
	$("#"+eval("tables[1]")).remove();
	//creating tabla
	$("#divProcessesList").append("<table id='"+eval("tables[1]")+"'></table>");
	$("#"+eval("tables[1]")).append("<tbody>")//for sorting
	//
	
	var row=1;
	for (var enumItems = new Enumerator(colItems); !enumItems.atEnd(); enumItems.moveNext()) {
		var objItem = enumItems.item();
		var row_over_style=""
		//
		ArrProcessesList.push()
		for(var zz=0;zz<=(ProcProps.length/3)-1;zz++){eval("ArrProcessesList["+(row-1)+"]."+ProcProps[zz*3]+"=objItem."+ProcProps[zz*3])}//fill array with processes info		
		//
		var td_beg="<td class='tabla1' onmouseDown='ContextMenu("+row+")'"
		var td_right=td_beg+" align='right'"				
		$("#tabla").append("<tr style='back1' id='table_row_"+row+"'>");
		//
		
		for(var zz=0;zz<=(ProcProps.length/3)-1;zz++){
			if(ProcProps[zz*3+1]=='str'){$("#table_row_"+row).append(td_beg  +" width="+ProcProps[(zz*3)+2]+">"+eval("ArrProcessesList["+(row-1)+"]."+ProcProps[zz*3])+"</td>");}
			else{$("#table_row_"+row).append(td_right +" width="+ProcProps[(zz*3)+2]+">"+eval("ArrProcessesList["+(row-1)+"]."+ProcProps[zz*3])/1024+" kb</td>");}
		}//fill the table
		row+=1;
	}
	$("#"+eval("tables[1]")).append("</tbody>")	
	//colorize tabla
	$("#"+eval("tables[1]")).colorize({bgColor:'#EAF6CC', hoverColor:'#f6a828', hiliteColor:'red', rows:true});
	//
	$("#"+eval("tables[1]")).tablesorter({headersTable:'tabla_h',afterSortFunction:"$('#"+eval("tables[1]")+"').colorize({bgColor:'#EAF6CC', hoverColor:'#f6a828', hiliteColor:'red', rows:true});"});
	GetProcessInfo(ActiveComputer,1)
	return true;
}

function ContextMenu(row){//
$('#tabla').contextMenu('myMenu1', {
		bindings: {
			'kill': function(t) {
				//alert(row-1)//debug
				var objWMIService = GetObject("winmgmts:\\\\" + objComputersList[ActiveComputer].Name + "\\root\\CIMV2");
				var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '"+ArrProcessesList[row-1].Caption+"' and ProcessId='"+ArrProcessesList[row-1].ProcessId+"'", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);
				for (var enumItems = new Enumerator(colItems); !enumItems.atEnd(); enumItems.moveNext()) {
					enumItems.item().Terminate;
				}
				alert('Sucessfully terminated '+ArrProcessesList[row-1].Caption);
				GetProcesses(ActiveComputer);
			},
			'run_new_process': function(t) {
				$('#dialog').dialog('open');
			},
			'info':function(t){
				GetProcessInfo(ActiveComputer,row-1)
				$('#tabs').tabs('select', 2);
			}
        }
      });
}
//
function ContextMenu_Computers(row){
	$('#tabla_computers').contextMenu('myMenu0', {
		bindings: {
			'info':function(t){
				ActiveComputer=row-1
				if(GetProcesses(ActiveComputer)==true){$('#tabs').tabs('select', 1)};
			}
        }
      });
}

function hide_show_alt(){
	if($('#altuser_value:checked').val()){
		$('#login_label').show();
		$('#password_label').show();
		}
	else
		{		
		$('#login_label').hide();
		$('#password_label').hide();
		}
	}

function init_window(){	

	//init tabs
	$("#tabs").tabs();
	//bind div resize function on tab select
	$("#tabs").bind('tabsselect', function(event, ui) {		
		setTimeout('tabSize('+ui.index+')',ResizeTimeout)		
		}
	);			
	//enable scrolling  for processes list
	document.getElementById('divProcessesList').style.overflow='auto';
	//process table columns size
	for(var z=1;z<=ProcProps.length/3;z++){eval("document.getElementById('processes_col"+(z-1)+"').style.width=ProcProps["+((z*3)-1)+"];")}//resize columns width with odd ProcProps fields
	//for(var z=0;z<=(ProcProps.length-1)/2;z++){eval("document.getElementById('processes_col"+z*z+"').style.width=ProcProps["+z*z+"];")}			
	//enable scrolling  for domain computers list
	document.getElementById('divPCList').style.overflow='auto';
	//resize computers list header
	for(var z=0;z<=(LdapProps.length-1)/2;z++){eval("document.getElementById('pc_col"+(z)+"').style.width=LdapProps["+((z*2)+1)+"];")}//resize columns width with odd LdapProps fields
	//for(var z=0;z<=8;z++){eval("document.getElementById('pc_col"+z+"').style.width=pc_col_width["+z+"];")}			
	//resize tab(0)
	tabSize(0)
	//enable scrolling  for process info 
	document.getElementById('divInfoList').style.overflow='auto';
	// ini run Dialog	
	init_run_dialog();		
	// Get Computers list
	GetDomainComputers();
	//filter
	$("#quickfind0").keyup(function() {
		$.uiTableFilter( $('#'+eval("tables[0]")), this.value );
	})
	$("#quickfind1").keyup(function() {
		$.uiTableFilter( $('#'+eval("tables[1]")), this.value );
	})	
	//debug hide
	if(debug){
	}	
	$('#divLoading').hide();
	
}	

function tabSize(tabID){	
		switch(tabID){
			case 0:
				var iReturnValue = 0;
				var elementid=document.getElementById('divPCList')
				while( elementid != null ){
					iReturnValue += elementid.offsetTop;
					elementid = elementid.offsetParent;
				}
				var vHeigth=StartPanelPosition-iReturnValue-bottom_space;
				//tabs2 elements
				document.getElementById('divPCList').style.height=vHeigth;
				document.getElementById('quickfind0').focus();
				//focus on find				
			case 1:				
				//get top of processes div
				var iReturnValue = 0;
				var elementid=document.getElementById('divProcessesList')
				while( elementid != null ){
					iReturnValue += elementid.offsetTop;
					elementid = elementid.offsetParent;
				}
				var vHeigth=StartPanelPosition-iReturnValue-bottom_space;
				//size proper size of processes table  				
				document.getElementById('divProcessesList').style.width=window.screen.width-right_space;	
				document.getElementById('divProcessesList').style.height=vHeigth;
			case 2:
				var iReturnValue = 0;
				var elementid=document.getElementById('divInfoList')
				while( elementid != null ){
					iReturnValue += elementid.offsetTop;
					elementid = elementid.offsetParent;
				}
				var vHeigth=StartPanelPosition-iReturnValue-bottom_space;
			
				//tabs2 elements
				document.getElementById('divInfoList').style.height=vHeigth;
			}
}

function init_run_dialog(){
	$('#login_label').hide();
	$('#login_label').hide();
	$('#password_label').hide();		
	$('#dialog').dialog({
		autoOpen: false,
		modal: true,
		width: 600,
		buttons: {
			"Run": function() { 
				pc=ArrProcessesList[1].Name
				//alert(pc)
				if($('#altuser_value:checked').val()){
					JSExecAs(pc,$('#run_value').val(),$('#login_value').val(),$('#password_value').val());
				}
				else{
					JSExec(pc,$('#run_value').val())
					
				}
				$(this).dialog("close"); 
				GetProcesses(ActiveComputer);
			}, 
			"Cancel": function() { 
				$(this).dialog("close"); 
			} 
		}
	});
	//$('#dialog').dialog('open');
}

function JSExec(e_pc,e_process){
	var objClass = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\"+e_pc+"\\root\\CIMV2:Win32_Process")
	var Res = objClass.Create(e_process, null, null, null)
}

function JSExecAs(e_pc,e_process,e_user,e_pass){

	var objSWbemLocator = new ActiveXObject("WbemScripting.SWbemLocator")
	var objServices = objSWbemLocator.ConnectServer(e_pc, "root\\CIMV2", e_user, e_pass, null, null, 0)
	var objClass = objServices.Get("Win32_Process")
	Res = objClass.Create(e_process, null, null, null)
}

//-->
</script>
</head>
<body onload="init_window();">
	<div id="tabs">	
		<ul>
			<li><a href="#tabs-1">Computers</a></li>
			<li><a href="#tabs-2">Processes</a></li>
			<li><a href="#tabs-3">Process Info</a></li>
			<li><a href="#tabs-4">About</a></li>
		</ul>	
		<div id="tabs-1">
		<!computers table/>
		<input type="text" id="quickfind0" width=500><br>
			<table id="tabla_h_computers">
				<thead>
					<tr>
						<th class='tabla2' id='pc_col0'>Name</th>
						<th class='tabla2' id='pc_col1'>dNSHostName</th>
						<th class='tabla2' id='pc_col2'>Last Logon</th>
						<th class='tabla2' id='pc_col3'>Logon Count</th>
						<th class='tabla2' id='pc_col4'>Operating System</th>
						<th class='tabla2' id='pc_col5'>Service Pack</th>
						<th class='tabla2' id='pc_col6'>System Version</th>
						<th class='tabla2' id='pc_col7'>Description</th>
						<th class='tabla2' id='pc_col8'>Location</th>
					</tr>
				</thead>
			</table>
			<div class="scrollbox" id="divPCList">
			</div>
		</div>		
		<div id="tabs-2">
		<input type="text" id="quickfind1" width=500><br>
		<!processes table/>
			<table id="tabla_h">
				<thead>
					<tr>
						<th class='tabla2' id='processes_col0'>Process</th>
						<th class='tabla2' id='processes_col1'>PID</th>
						<th class='tabla2' id='processes_col2'>Working Set</th>
						<th class='tabla2' id='processes_col3'>PrivatePageCount</th>
						<th class='tabla2' id='processes_col4'>VirtualSize</th>
						<th class='tabla2' id='processes_col5'>ExecutablePath</th>
					</tr>
				</thead>
			</table>
			<div class="scrollbox" id="divProcessesList">
			</div>
		</div>
		<div id="tabs-3">
			<div class="scrollbox" id="divInfoList">
			</div>
		</div>	
		<div id="tabs-4">
			<p>HTA process explorer by Dudka</p>
			<p>alexey@yandex.ru</p>
		</div>
	</div>	
	<!run dialog div/>
	<div id="dialog" title="Start Process">
		<div id="run_label">
			<div id="run_text" class="label"><p>local process path</p></div><input type="text" size="45" id="run_value">
		</div>
		<div id="altuser_label">
			<div id="altuser_text"class="label2"><p>use alternative security credential's</p></div><input type="CHECKBOX" id="altuser_value" onclick="hide_show_alt()">
		</div>
		<div id="login_label">
			<div id="login_text"class="label"><p>user</p></div><input type="text" size="20" id="login_value">
		</div>
		<div id="password_label">
			<div id="password_text"class="label"><p>password</p></div><input type="password"size="20"id="password_value">
		</div>
	</div>

	<!context menu for processes/>
	<div class="contextMenu" id="myMenu1" style="position:'absolute';width='200px'">
		<ul>
			<li id="info">Info</li>
			<li id="kill">Kill</li>
			<li id="run_new_process">Run new</li>
		</ul>		
	</div>
	<!context menu for computers/>
	<div class="contextMenu" id="myMenu0" style="position:'absolute';width='200px'">
		<ul>
			<li id="info">Processes info</li>
		</ul>		
	</div>
	
</body>